3.3. Importing the Data
The next step is to copy the data into the cloud—specifically, to your SQL Azure TechBio database. The syntax for copying into a database is very similar to the syntax for copying data out. You use the in keyword and specify the server name and credentials for your SQL Azure database, as shown in Figure 18.
After you type in the
command, press Enter to execute the bcp utility. Only one row is copied
over, and then an error is generated, stating that an unexpected
end-of-file (EOF) was encountered. This error isn't specific to SQL
Azure; the bcp utility has issues with columns of the uniqueidentifier data type. You can find posts and blogs all over the Internet about this problem.
The solution is to execute the following T-SQL against the Users table in your SQL Azure database:
alter table users
drop column rowguid
The cool thing is that you don't need to re-export the data. You can re-execute the bcp import command. Do that, as shown in Figure 19, and all 105 rows are imported. Then, use the same syntax to import the Docs and UserDocs data.
Don't forget to put the rowguid column back on the Users table. You can do this by using the same syntax as before:
ALTER TABLE Users
ADD rowguid uniqeidentifier
Next, let's make this a
little simpler and put the export and import together, so you aren't
running the statements one at a time.
3.4. Putting the Export and Import Together
You can put the export and
import processes together into a single file to make them easier to use.
To do so, open Notepad, and type in the following, replacing the
italicized information with the appropriate information for your
environment:
bcp Techbio.dbo.Users out c:\scott\user.dat -S Scott-PC -U sa -P Password -n -q
bcp Techbio.dbo.Docs out c:\scott\docs.dat -S Scott-PC -U sa -P Password -n -q
bcp Techbio.dbo.UserDocs out c:\scott\userdoc.dat -S Scott-PC -U sa -P Password -n -q
bcp Techbio.dbo.Users in c:\scott\user.dat -S servername.database.windows.net
-U SQLScott@ servername -P #ackThis -n -q
bcp Techbio.dbo.docs in c:\scott\docs.dat -S servername.database.windows.net
-U SQLScott@ servername -P #ackThis -n -q
bcp Techbio.dbo.userdocs in c:\scott\userdoc.dat -S servername.database.windows.net
-U SQLScott@ servername -P #ackThis -n -q
Save the file as AzureBCP.cmd, and navigate to its location.
Double-click the file to execute it. A command window appears, showing the results of the bcp commands that export and import the data.
As stated earlier, SQL
Server BOL is full of information about how to use the bcp utility. This
section is a brief introductory look at how to use this utility to move
data from your local SQL Server instance to SQL Azure. The bcp utility
is bulk-copy method of moving data. It lacks SSIS's ability to convert
data from one data type to another, and SSIS's workflow components. But
if all you're interested in is moving data from one table to a similar
destination table, bcp is your best friend.